package lesson1;



public class CheckingAccount {
    
    static{
        System.out.println("CheckingAccount class has been loaded and initialized");
    }
    
    // default initializer
    // what's the purpose of this? if there are single variables to be
    // explicitly initialized before the constructor is invoked,
    // then place them in here.
    {
        System.out.println("CheckingAccount default initializer invoker");
        name = "";
        ssn = "";
    }
    
    private String name;
    private String ssn;
    private double balance;
    
    public CheckingAccount(){
        System.out.println("CheckingAccount constructure invoked");
        balance = 0.0;
    }
    
    public CheckingAccount(String n, String s, double b){
        name = n;
        ssn = s;
        balance = b;
    }
    
    public double withdraw(double amount){
        balance = balance - amount;
        return balance;
    }
    
    public double deposit(double amount){
        balance = balance + amount;
        return balance;
    }
    
    @Override
    public boolean equals(Object ca){
        System.out.println("CheckingAccount.equals invoked");
        
        if(ca instanceof CheckingAccount){
            CheckingAccount in = (CheckingAccount) ca;
            return (in.name.equals(name) && in.ssn.equals(ssn) && in.balance == balance);
        }
        
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 59 * hash + (this.ssn != null ? this.ssn.hashCode() : 0);
        hash = 59 * hash + (int) (Double.doubleToLongBits(this.balance) ^ (Double.doubleToLongBits(this.balance) >>> 32));
        return hash;
    }

    @Override
    public String toString() {
        return "CheckingAccount{" + "name=" + name + ", ssn=" + ssn + ", balance=" + balance + '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSsn() {
        return ssn;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }
}
